
footer.init();
header.init('申请提现');
app.ajax(
	'/Member/Shop/withdrawal',
	null,
	function(res){
		if(res.code ==200){
			var mess={};
			if(window.sessionStorage.getItem('choice_account')){
				mess=window.sessionStorage.getItem('choice_account');
				console.log(JSON.parse(mess));
				mess = JSON.parse(mess);
				console.log(mess);
				
				res.info.id = mess.id;
				res.info.account_name = mess.account_name;
				res.info.account_type = mess.account_type;
				res.info.name = mess.name;
			}
			app.tpl($('.withDrawals'),'tpl-withDrawals',res);
		}else{
			layer.msg('网络繁忙，请稍候再试');
		}
	});
window.onload = function(){
	$('body').on('click','.account-choice',function(){
		app.open('shop.choiceAccount.html','shop_choice_acco',{},window.location.href,document.body.scrollTop);		
	});
	
	$('body').on('click','.getCode',function(){
		var tel =$(this).attr('data-mobile');
		var btn =$(this);
		app.ajax(
			'/Index/Index/send',
			{
				mobile : tel
			},function(res){
				 $(".getCode").text("发送成功");
				 var time = 60;
               hander = setInterval(function () {
                    if (time <= 0) {
                        canSend = true;
                        clearInterval(hander);
                        btn.text("获取验证码");
                        btn.removeAttr("disabled");
                    }
                    else {
                        canSend = false;
                        time--;
                        btn.attr({ "disabled": "disabled" });
                        btn.text( time + "s后可重发");
                }
			},1000);
		});
	});
	
	$('body').on('input','#getCashNum',function(){
		$('p.prompt').fadeIn();
		var num =parseFloat($(this).val());
		if(num%100 != 0){
			$('.prompt').html('请输入100的倍数');
			return false;
		}  
		var totalM = parseFloat($('[data-account]').attr('data-account'));
		console.log($('[data-account]').attr('data-account'));
		var s = (totalM - num).toFixed(2);
		if(s < 0 ){
			$('p.prompt').html('输入金额超额');
			return false;
		}
		$('[data-account]').text(s);
		$('p.prompt').stop().fadeOut();
	});
	
	$('body').on('click','.applyCash',function(){
		var num =parseFloat($('#getCashNum').val());
		var id = $(this).attr('data-id');
		if(($('#getCashNum').val()).length <3){return false;}
		if(num%100 != 0){
			layer.msg('请输入100的倍数');
			return false;
		}  
		app.ajax(
			'/Member/Shop/withdrawal_sub',
			{
				id : id,
				apply_money : num
			},function(res){
				if(res.code == 200){
					layer.msg('您的提现申请已经提交，等到审核');
					setTimeout(function(){
						history.go(-1);
					},2000);
				}else{
					layer.msg(res.msg);
				}
		});
	});
}
